;;; init-exec-path.el -*- lexical-binding: t; -*-

;; Make sure exec-path-from-shell-initialize just execute once
(defvar canary--exec-path-from-shell-loaded-p nil)
(define-advice exec-path-from-shell-initialize (:around (orig-fn &rest args))
  "Cache exec-path-from-shell-initialize"
  (if canary--exec-path-from-shell-loaded-p
      (message "All shell environment variables has loaded, yow!")
    (setq canary--exec-path-from-shell-loaded-p t)
    (apply orig-fn args)))

(when (or *sys-is-linux-x*
          *sys-is-mac-x*)
  (use-package exec-path-from-shell
    :demand
    :config
    (setq exec-path-from-shell-check-startup-files nil)
    (dolist (var '("LANG"))
      (add-to-list 'exec-path-from-shell-variables var))
    (setq exec-path-from-shell-arguments '("-l"))
    (exec-path-from-shell-initialize)))

(provide 'init-exec-path)
